import { http } from '@/api/request'

function fnGetTaskList(type: string) {
  return http.get(`/operations/tasks?task_type=${type}`);
}

function fnAddTask(params: {
  name: string,
  assets: string,
  hosts: string,
  task_type: string,
})  {
  return http.post('/operations/tasks', params);
}

function fnGetInspectionAsset(type: string) {
  return http.get(`/operations/asset${type ? `?task_type=${type}` : ''}`);
}

function fnUpload(file: FormData) {
  return http.post('/operations/asset', file, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

function fnTaskAttention(params: {
  task_id: string,
  action: string,
}) {
  return http.post('/operations/tasks', params);
}

function fnGetDetailByTaskId(id: number) {
  return http.get(`/operations/tasks?task_id=${id}`);
}

function fnDownloadReportById(id: number) {
  return http.get(`/operations/tasks/download/${id}`, {
    'content-type': 'application/x-download',
    responseType: 'blob',
  });
}

function fnDownloadReport(param: any) {
  return http.post(`/operations/tasks/download/${param.task_id}`,param, {
    'content-type': 'application/x-download',
    responseType: 'blob',
  });
}

function fnBatchDeleteTask(idList: number[]) {
  return http.delete('/operations/tasks', {task_ids:idList });
}

function fnDeleteTask(id: number) {
  return http.delete('/operations/tasks',  {task_id:id});
}

function fnDeleteAsset(params: any) {
  return http.delete('/operations/asset', { data: params });
}

function fnDownLoadAsset(param: any) {
  return http.post('operations/asset/download', param, {
    'content-type': 'application/x-download',
    responseType: 'blob',
  });
}

function fnQueryAssetsItem(params: any) {
  return http.post('/operations/tasks/host_items_result', params);
}

function fnQueryTaskResult(params: any) {
  return http.post('/operations/tasks/result', params);
}



export const osManagerApi = {
  fnGetTaskList,
  fnAddTask,
  fnGetInspectionAsset,
  fnTaskAttention,
  fnDownloadReportById,
  fnDownloadReport,
  fnGetDetailByTaskId,
  fnBatchDeleteTask,
  fnDeleteTask,
  fnDeleteAsset,
  fnDownLoadAsset,
  fnUpload,
  fnQueryAssetsItem,
  fnQueryTaskResult,
}
